const ResourceModel = require("@/model/Resource");
const z_base_Dao = require("@/dao/z_base");

const resource = {
  async GetListByKeyword(keyword) {
    let list = [];
    //关键字可以无
    if (keyword) {
      // 模糊查询
      list = await z_base_Dao.ListByCondition(
        ResourceModel.Resource,
        "name",
        keyword
      );
    } else {
      list = await z_base_Dao.List(ResourceModel.Resource);
    }
    return list;
  },
  // 根据 [资源id列表] 获取 [资源列表]
  async GetListByIds(ids) {
    const [rows] = await global.mysqlPool.execute(
      `select url,request_method from resource where id IN (${ids.join(",")})`
    );
    return rows;
  },
};

module.exports = resource;
